# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        博智科技  
# Name:         demo1724
# Description:
# Author:       yzl
# Date:         2019-02-08
#-------------------------------------------------------------------------------

import _thread as thread
from time import sleep,ctime

def func(index,sec,lock):
    print('开始执行',index,'执行时间',ctime())
    sleep(sec)
    print('执行结束', index, '结束时间', ctime())
    # 线程函数执行完毕,释放线程锁
    lock.release()

def main():
    # 1 创建线程锁对象
    lock1 = thread.allocate_lock()
    # 2 获取线程锁
    lock1.acquire()

    # 开启一个线程
    thread.start_new_thread(func,(10,4,lock1))

    lock2 = thread.allocate_lock()
    lock2.acquire()

    thread.start_new_thread(func, (20, 2, lock2))

    while lock1.locked() or lock2.locked():
        #print('等待线程函数运行中...')
        pass

if __name__ == '__main__':
    main()



